<template>
  <!-- 添加或修改生产过程数据对话框 -->
  <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-tabs v-model="activeName" class="detail-tab" type="card">
        <el-tab-pane label="基本信息" name="first">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="产品名称" prop="goodsName">
                <el-input v-model="form.goodsName" placeholder="请输入产品名称" disabled/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="产品型号" prop="goodsModel">
                <el-input v-model="form.goodsModel" placeholder="请输入产品型号" disabled/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="生产批号" prop="batchNumber">
                <el-input v-model="form.batchNumber" placeholder="请输入生产批号"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="系统推送" prop="processMethod">
                <el-input v-model="form.processMethod" placeholder="请输入系统推送"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="加工件数" prop="processCount">
                <el-input v-model="form.processCount" placeholder="请输入加工件数"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="生产完成时间" prop="finishTime">
                <el-date-picker clearable
                                v-model="form.finishTime"
                                type="datetime"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择生产完成时间">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="质检报告" prop="reportFile">
                <file-upload v-model="form.reportFile"/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {addAction, getAction, getById, updateAction} from '@/api/manage';
import moment from 'moment';

export default {
  name: "FactoryProductProcessForm",
  data() {
    return {
      // 遮罩层
      loading: true,
      activeName: "first",
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      url: {
        getById: '/factoryProductProcess/factoryProductProcess/',
        add: '/factoryProductProcess/factoryProductProcess/add',
        edit: '/factoryProductProcess/factoryProductProcess/edit',
      },
    };
  },
  created() {
  },
  methods: {
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectId: null,
        orderId: null,
        goodsId: null,
        goodsName: null,
        daohuoDetailId: null,
        rukuId: null,
        goodsModel: null,
        batchNumber: null,
        processMethod: null,
        processCount: null,
        finishTime: null,
        testPass: '1',
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加生产过程数据";
    },

    /** 新增按钮操作 */
    handleAddByWorkOrderId(workOrder) {
      this.reset();
      this.form.workOrderId = workOrder.id;
      this.form.goodsName = workOrder.productName;
      this.form.goodsModel = workOrder.materialsDescription;
      this.open = true;
      this.title = "添加生产过程数据";
    },

    /** 新增按钮操作 */
    handleAddByDaohuoDetailId(daohuoDetailId,goodsId) {
      let that = this;
      that.reset();
      that.form.daohuoDetailId=daohuoDetailId;
      that.form.goodsId = goodsId;
      that.open = true;
      that.title = "添加生产过程试验数据";
    },

    /** 新增按钮操作 */
    handleAddByProduceDetailId(produceRecordDetailId,goodsId) {
      this.reset();
      this.form.produceRecordDetailId = produceRecordDetailId;
      this.form.goodsId = goodsId;
      this.open = true;
      this.title = "添加生产过程试验数据";
    },

    /** 新增按钮操作 */
    handleAddByRukuId(rukuId,goodsId,goodsSaleId) {
      this.reset();
      this.form.rukuId = rukuId;
      this.form.goodsId = goodsId;
      this.form.goodsSaleId = goodsSaleId;
      this.open = true;
      this.title = "添加生产过程试验数据";
    },

    /** 新增按钮操作 */
    handleAddByGoodsSaleId(goodsSaleId,goodsId) {
      this.reset();
      this.form.goodsSaleId = goodsSaleId;
      this.form.goodsId = goodsId;
      this.open = true;
      this.title = "添加生产过程试验数据";
    },

    /** 新增按钮操作 */
    handleAddByFahuoDetailId(fahuoDetailId) {
      this.reset();
      this.form.fahuoDetailId = fahuoDetailId;
      this.open = true;
      this.title = "添加生产过程试验数据";
    },





    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getById(this.url.getById, id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改生产过程数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAction(this.url.edit, this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.$emit('ok');
            });
          } else {
            addAction(this.url.add, this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.$emit('ok');
            });
          }
        }
      });
    },

    getStandardList() {
      let name = "factory_product_process";
      let goodsId = this.form.goodsId;
      getAction('/factoryTestStandard/factoryTestStandard/getTableColumns/' + name + "/" + goodsId, {}).then(response => {
        this.loading = false;
        this.standardList = response.data;
      });
    }



  }
};
</script>
